package cn.iocoder.yudao.module.lfd.dal.mysql.appointment;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.lfd.dal.dataobject.appointment.AppointmentDO;
import cn.iocoder.yudao.module.lfd.dal.dataobject.appointment.AppointmentListDO;
import cn.iocoder.yudao.module.lfd.dal.dataobject.appointment.AppointmentStatictis;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.lfd.controller.admin.appointment.vo.*;
import org.apache.ibatis.annotations.Param;

/**
 * 预约 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface AppointmentMapper extends BaseMapperX<AppointmentDO> {

    Page<AppointmentListDO> listPage(@Param("page") Page<AppointmentForm> page, @Param("form") AppointmentForm form);

    List<AppointmentStatictis> statictis(@Param("start") LocalDateTime start, @Param("end") LocalDateTime end);


    default List<AppointmentDO> selectList(AppointmentExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<AppointmentDO>()
                .eqIfPresent(AppointmentDO::getOpenid, reqVO.getOpenid())
                .eqIfPresent(AppointmentDO::getFlowNo, reqVO.getFlowNo())
                .eqIfPresent(AppointmentDO::getShopId, reqVO.getShopId())
                .betweenIfPresent(AppointmentDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(AppointmentDO::getStatus, reqVO.getStatus())
                .eqIfPresent(AppointmentDO::getBarberId, reqVO.getBarberId())
                .eqIfPresent(AppointmentDO::getMoney, reqVO.getMoney())
                .eqIfPresent(AppointmentDO::getHairDate, reqVO.getHairDate())
                .betweenIfPresent(AppointmentDO::getStartHairTime, reqVO.getStartHairTime())
                .orderByDesc(AppointmentDO::getId));
    }


   default List<AppointmentDO> selectByToDayStatus(Long shopId, Long barberId,List<AppointmentEnum> asList){
       QueryWrapper<AppointmentDO> query = new QueryWrapper<>();
       query.eq("shop_Id", shopId);
       query.eq("barber_Id", barberId);
       query.eq("hair_date", LocalDate.now());
       query.in("status", asList);
       return selectList(query);
   };

}
